package com.xc.mapper;

import com.xc.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

/**
 * 员工管理
 */
@Mapper
public interface EmpMapper {
    //获取全部用户
    /*
    @Select("select count(*)")
    public abstract long countTotal();
    */

    //获取 limit 每页显示数据
    //limit(（跳过）开始索引，每页个数)
    /*
    @Select("select * from emp limit #{start},#{end}")
    public abstract List<Emp> selectByPage(Integer start, Integer end);
    */

    @Select("select * from emp where id = #{id}")
    public Emp selectById(Integer id);

    //用分页插件查询全部,分页插件自动加 limit
    //@Select("select * from emp")
    public abstract List<Emp> selectAllAndCondation(String name, Short gender, LocalDate start, LocalDate end);

    //添加数据
    @Insert("insert into emp values(#{id},#{username},#{password},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    public int insert(Emp emp);

    //修改数据
    //虽然有service层设置了更新时间，但是也要写进数据库，这里也要加。只看传过来的对象，不看谁写的数据，管他前端后端，只要想改就要在这里写
    //@Update("update emp set username = #{username}, name = #{name}, gender = #{gender}, image = #{image}, job = #{job}, entrydate = #{entrydate}, dept_id = #{deptId},update_time = #{updateTime} where id = #{id}")
    public int update(Emp emp);

    //删除数据
    //删除把批量跟单个一起写了，不分两次了
    //@Delete("delete from emp where id = #{id}")
    public int delete(Integer[] ids);

    //登录查询
    @Select("select * from emp where username = #{username} and password = #{password}")
    public Emp login(Emp emp);

    //根据部门删除员工
    @Delete("delete from emp where dept_id = #{id}")
    int deleteEmpByDeptId(Integer id);
}
